﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
}
<div  class="liger-form" style="padding-top: 10px">
    <table cellpadding="0" cellspacing="0" class="l-table-edit">
        <tr>
            <td align="right" class="l-table-edit-td">
                会员类型:
            </td>
            <td align="left" class="l-table-edit-td">
                <select name="ddlType" id="ddlType">
                    <option value="-1">全部</option>
                    <option value="1">投资人</option>
                    <option value="2">借款人</option>
                </select>
            </td>
            <td align="right" class="l-table-edit-td">
                用户名/姓名:
            </td>
            <td align="left" class="l-table-edit-td">
                <input name="txtUserCode" type="text" id="txtUserName" ltype="text" />
            </td>
            <td align="right" class="l-table-edit-td">
                身份证:
            </td>
            <td align="left" class="l-table-edit-td">
                <input name="txtUserCode" type="text" id="txtUserIDCard" ltype="text" style="width: 250px" />
            </td>
            <td align="left" class="l-table-edit-td" rowspan="2" valign="bottom">
                <input type="button" value="查询" id="btnSearch" onclick="search()" style="background: url('../../Content/roohui/ligerUI/skins/icons/search2.gif') no-repeat"
                    class="l-button" />
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                是否激活:
            </td>
            <td align="left" class="l-table-edit-td">
                <select name="ddlActive" id="ddlActive">
                    <option value="-1">全部</option>
                    <option value="1">已激活</option>
                    <option value="0">未激活</option>
                </select>
            </td>
            <td align="right" class="l-table-edit-td">
                手机:
            </td>
            <td align="left" class="l-table-edit-td">
                <input name="txtHandPhone" type="text" id="txtHandPhone" ltype="text" />
            </td>
            <td align="right" class="l-table-edit-td">
                邮箱:
            </td>
            <td align="left" class="l-table-edit-td">
                <input name="txtEmail" type="text" id="txtEmail" ltype="text" style="width: 250px" />
            </td>
        </tr>
    </table>
</div>
<div id="membergrid">
</div>
<script type="text/javascript">
    var membergrid;
    $(function () {
        membergrid = $("#membergrid").ligerGrid({
            columns: [
                {
                    display: '用户名', isAllowHide: false,width: '15%', isSort: false,
                    render: function (row) {

                        var html = '<a href="#" title="点击查看用户基本信息" onclick="ViewBaseDetail(\'' + row.UserName + '\',\'' + row.RealName + '\')">' + row.UserName + '</a>';
                        
                        return html;
                    }
                },
                { display: '真实姓名', name: 'RealName', width: '10%', isSort: false },
                { display: '身份证号', name: 'IDCardNo', width: '15%', isSort: false },
                { display: '手机', name: 'HandPhone', width: '10%', isSort: false },
                { display: '邮箱', name: 'Email', width: '15%', isSort: false },
                { display: '类型', name: 'MemberType', width: '8%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.MemberType) == 1) return '投资人';
                        else if (parseInt(item.MemberType) == 2) return '借款人';
                        return '未知';
                    }
                },
                { display: '是否激活', width: '5%', isSort: false,
                    render: function (item) {
                        if (item.IsActive) return '已激活';
                        return '未激活';
                    }
                },
                { display: '状态', name: 'Status', width: '5%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == 1) return '正常';
                        return '禁用';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {

                        var html = '<a href="#" onclick="ViewDetail(\'' + row.UserName + '\',\'' + row.RealName + '\')">详细信息</a>';
                        if (row.Status == 1) {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.UserName + '\',0,\'' + row.RealName + '\')">禁用</a>';
                        }
                        else {
                            html = html + '&nbsp;&nbsp;<a href="#" onclick="changestate(\'' + row.UserName + '\',1,\'' + row.RealName + '\')">启用</a>';
                        }

                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Member/GetMemberListByPage",
            pageSizeOptions: [10],
            pageSize: 10
        });
    });
    function search() {
        membergrid.setOptions(
             {
                 parms:
                [
                    { name: "userName", value: $("#txtUserName").val() },
                    { name: "idCardNo", value: $("#txtUserIDCard").val() },
                    { name: "email", value: $("#txtEmail").val() },
                    { name: "handPhone", value: $("#txtHandPhone").val() },
                    { name: "memberType", value: $("#ddlType").val() },
                    { name: "activeStatus", value: $("#ddlActive").val() },
                    { name: "page", value: 1 }
                ]
             });
             membergrid.loadData();
         }
         function changestate(userName, state, realName) {
             var statestr = "禁用";
             if (state == 1) {
                 statestr = "启用";
             }
             $.ligerDialog.confirm('确定【' + statestr + '】会员[' + realName + ']吗？', '温馨提示', function (result) {
                 if (result) {
                     $.ajax({
                         url: '/Member/MemberChangeStatus',
                         data: "userName=" + userName + "&status=" + state,
                         type: "post",
                         success: function (result) {
                             if (result == "1") {
                                 //employee.deleteSelectedRow();
                                 $.ligerDialog.success(statestr + "会员成功");
                                 search();
                             } else {
                                 $.ligerDialog.error(statestr + "会员失败！", '温馨提示');
                             }
                         }
                     });
                 }
             });
         }
         function ViewBaseDetail(userName, realName) {
             $.ajax({
                 url: '/Member/GetMemberByUserName',
                 data: "userName=" + userName,
                 type: "post",
                 success: function (result) {
                     //result.RID,result.Data
                      
                     result = result.replace(/:null/g, ":\"\"");
                     result = eval("(" + result + ")");
                     if (result.RID == "1") {
                         var mtype = result.Data.MemberType == 1 ? '投资人' : '借款人';
                         var active = result.Data.IsActive ? '已激活' : '未激活';
                         var status = result.Data.Status == 1 ? '正常' : '已禁用';
                         var gender = '未知';
                         if (result.Data.Gender == 0) {
                             gender = '男';
                         }
                         else if (result.Data.Gender == 1) {
                             gender = '女';
                         }
                         var checkhtml = "";
                         if (result.Data.IDCardCheck) {
                             checkhtml += '<img alt="身份证已认证" src="/content/images/id.gif"/>';
                         }
                         else {
                             checkhtml += '<img alt="身份证未认证" src="/content/images/id_0.gif"/>';
                         }

                         if (result.Data.HandPhoneCheck) {
                             checkhtml += '<img alt="手机已认证" src="/content/images/phone.gif"/>';
                         }
                         else {
                             checkhtml += '<img alt="手机未认证" src="/content/images/phone_0.gif"/>';
                         }
                         if (result.Data.EmailCheck) {
                             checkhtml += '<img alt="邮箱已认证" src="/content/images/email.gif"/>';
                         }
                         else {
                             checkhtml += '<img alt="邮箱未认证" src="/content/images/email_0.gif"/>';
                         }

                         var html = '<table cellpadding="0" cellspacing="0" class="l-table-edit"><tr>'
                        + '<td align="right" class="l-table-edit-td">用户名:</td><td align="left" class="l-table-edit-td">' + result.Data.UserName + '</td>'
                        + '<td align="right" class="l-table-edit-td">认证情况:</td><td align="left" class="l-table-edit-td">' + checkhtml + '</td>'
                        + '</tr><tr>'
                        + '<td align="right" class="l-table-edit-td">真实姓名:</td><td align="left" class="l-table-edit-td">' + result.Data.RealName + '</td>'
                        + '<td align="right" class="l-table-edit-td">会员类型:</td><td align="left" class="l-table-edit-td">' + mtype + '</td>'
                         + '</tr><tr>'
                          + '<td align="right" class="l-table-edit-td">性别:</td><td align="left" class="l-table-edit-td">' + gender + '</td>'
                        + '<td align="right" class="l-table-edit-td">注册IP:</td><td align="left" class="l-table-edit-td">' + result.Data.RegisterIP + '</td>'
                         + '</tr><tr>'
                         + '<td align="right" class="l-table-edit-td">移动电话:</td><td align="left" class="l-table-edit-td">' + result.Data.HandPhone + '</td>'
                        + '<td align="right" class="l-table-edit-td">身份证:</td><td align="left" class="l-table-edit-td">' + result.Data.IDCardNo + '</td>'
                          + '</tr><tr>'
                         + '<td align="right" class="l-table-edit-td">学历:</td><td align="left" class="l-table-edit-td">' + result.Data.Education + '</td>'
                        + '<td align="right" class="l-table-edit-td">邮箱:</td><td align="left" class="l-table-edit-td">' + result.Data.Email + '</td>'
                        + '</tr><tr>'
                         + '<td align="right" class="l-table-edit-td">婚姻:</td><td align="left" class="l-table-edit-td">' + result.Data.MaritalStatus + '</td>'
                        + '<td align="right" class="l-table-edit-td">居住地:</td><td align="left" class="l-table-edit-td">' + result.Data.Address + '</td>'
                         + '</tr><tr>'
                          + '<td align="right" class="l-table-edit-td">注册人:</td><td align="left" class="l-table-edit-td">' + result.Data.CreateUser + '</td>'
                        + '<td align="right" class="l-table-edit-td">注册时间:</td><td align="left" class="l-table-edit-td">' + result.Data.CreateTime.replace(/T/g, " ") + '</td>'
                         + '</tr><tr>'
                         + '<td align="right" class="l-table-edit-td">是否激活:</td><td align="left" class="l-table-edit-td">' + active + '</td>'
                        + '<td align="right" class="l-table-edit-td">当前状态:</td><td align="left" class="l-table-edit-td">' + status + '</td>'
                          + '</tr><tr>'
                          + '</table>';
                         $.ligerDialog.open({
                             title: '会员【' + realName + '】的基本资料',
                             id: 'viewDialog',
                             name: 'viewDialog',
                             slide: false,
                             isHidden: false,
                             modal: true,
                             content: html,
                             width: 500, isResize: false, allowClose: false,
                             buttons: [
                            {
                                text: '关闭', onclick: function (item, dialog) {
                                    dialog.hide();
                                }
                            }
                        ]
                         });

                     } else {
                         $.ligerDialog.warn("查看会员【" + realName + "】基本资料失败！", '温馨提示');
                     }
                 }
             });
         }
</script>
